package com.moinut.studentattendancemanager.model.dao.proxy;

import com.moinut.studentattendancemanager.model.dao.ITeacherDAO;
import com.moinut.studentattendancemanager.model.dao.impl.TeacherDAOImpl;
import com.moinut.studentattendancemanager.model.vo.db.Teacher;

import java.util.List;

/**
 * @author MOILING
 */
public class TeacherDAOProxy extends BaseDAOProxy<TeacherDAOImpl> implements ITeacherDAO {
    @Override
    public Teacher findLogin(Teacher teacher) throws Exception {
        Teacher getTeacher = this.dao.findLogin(teacher);
        this.databaseConnection.close();
        return getTeacher;
    }

    @Override
    public Teacher getTeacherById(String teacherId) throws Exception {
        Teacher getTeacher = this.dao.getTeacherById(teacherId);
        this.databaseConnection.close();
        return getTeacher;
    }

    @Override
    public List<Teacher> getAllTeachers() throws Exception {
        List<Teacher> teachers = this.dao.getAllTeachers();
        this.databaseConnection.close();
        return teachers;
    }

    @Override
    public boolean updateTeacherInfo(String oldId, Teacher newTeacher) throws Exception {
        boolean flag = this.dao.updateTeacherInfo(oldId, newTeacher);
        this.databaseConnection.close();
        return flag;
    }

    @Override
    public boolean updateTeacherPassword(String oldId, String newPassword) throws Exception {
        boolean flag = this.dao.updateTeacherPassword(oldId, newPassword);
        this.databaseConnection.close();
        return flag;
    }

    @Override
    public boolean updateTeacherEmail(String teacherId, String newEmail) throws Exception {
        boolean flag = this.dao.updateTeacherEmail(teacherId, newEmail);
        this.databaseConnection.close();
        return flag;
    }

    @Override
    TeacherDAOImpl setDAOImpl() {
        return new TeacherDAOImpl(this.databaseConnection.getConnection());
    }
}
